package com.book.service.impl;

import com.book.dao.book.BookDao;
import com.book.dao.book.impl.BookDaoImpl;
import com.book.dao.borrow.BorrowDao;
import com.book.dao.borrow.impl.BorrowDaoImpl;
import com.book.dao.reader.ReaderDao;
import com.book.dao.reader.impl.ReaderDaoImpl;
import com.book.pojo.Book;
import com.book.pojo.BorrowRecord;
import com.book.pojo.Reader;
import com.book.service.ReaderService;

import java.util.List;


public class ReaderServiceImpl implements ReaderService {
    private ReaderDao readerDao = new ReaderDaoImpl();
    private BorrowDao borrowDao = new BorrowDaoImpl();
    private BookDao bookDao = new BookDaoImpl();
    @Override
    public Reader login(Reader reader) {
        Reader dbReader = readerDao.getReaderByUsername(reader.getUsername());
        if (dbReader != null && dbReader.getPassword().equals(reader.getPassword())) {
            return dbReader; // 登录成功
        }
        return null; // 登录失败
    }

    @Override
    public int register(Reader reader) {
        return 0;
    }

    @Override
    public Reader findReaderById(int id) {
        return null;
    }
    @Override
    //归还图书
    public int returnBook(int borrowRecordId){
        return borrowDao.returnBook(borrowRecordId);
    }
    //借阅图书
    @Override
    public int addBorrowRecord(BorrowRecord borrowRecord){
        return borrowDao.addBorrowRecord(borrowRecord);
    }
    //查询所有图书
    @Override
    public List<Book> findAllBooks() {
        List<Book> allBooks = bookDao.findAllBooks();
        return allBooks;
    }
    //查询自己借的书
    @Override
    public  List<BorrowRecord> findBorrowRecordsByReaderId(int readerId){
        return borrowDao.findBorrowRecordsByReaderId(readerId);
    }
}
